<template>
  <div>
    <van-nav-bar
      title="编辑地址"
      left-text="返回"
      left-arrow
      @click-left="Esc"
    />
    <van-address-edit
      show-delete
      :show-area="false"
      show-set-default
      :address-info="address"
      :search-result="serch"
      @save="onSave"
      @delete="del"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      serch: [
        {
          name: "黄龙万科中心",
          address: "杭州市西湖区",
        },
        {
          name: "岳阳职业技术学院",
          address: "八栋",
        },
      ],
      address: {},
    };
  },
  methods: {
    Esc() {
      this.$router.replace("/address");
    },
    // 编辑
    async onSave(contect) {
      let res = await this.$post(this.url + "user/update/contect", {
        userId: this.address.userId,
        id: this.address.id,
        name: contect.name,
        mobile: contect.tel,
        contactFlag: contect.isDefault ? 1 : 0,
        address: contect.address,
      });
      if (!res.errorCode == "0") return;
      this.$notify({ type: "success", message: "修改成功" });
      this.$router.replace("/address");
    },

    // 删除
    async del() {
      let res = await this.$post(this.url + "user/remove/contect", {
        userId: this.address.userId,
        id: this.address.id,
      });
      if (res.errorCode == "0") {
        this.$notify({ type: "danger", message: "删除成功" });
        this.$router.replace("/address");
      }
    },
  },
  created() {
    this.address = this.Sto.Session.get("address");
    this.address.addressDetail = this.address.address;
  },
};
</script>

<style  scoped>
</style>